package com.pinda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pinda.base.entity.PdTruck;
import com.pinda.commonutils.Page;
import com.pinda.commonutils.Result;

import com.pinda.commonutils.StatusCode;

import com.pinda.commonutils.utils.Constant;
import com.pinda.mapper.PdTruckMapper;
import com.pinda.service.IPdTruckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pinda.vo.TruckVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 车辆信息表 服务实现类
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@Service
@Slf4j
public class PdTruckServiceImpl extends ServiceImpl<PdTruckMapper, PdTruck> implements IPdTruckService {


    @Autowired
    PdTruckMapper pdTruckMapper;



    @Override
    public Result queryPageTruck(Page<PdTruck> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        PageInfo<TruckVo> pdTruckPageInfo = new PageInfo<>(this.pdTruckMapper.queryPageTruck(page.getSearch()));
        if(pdTruckPageInfo!=null){
            log.debug("===================="+pdTruckPageInfo);
            return new Result(true, StatusCode.OK,"成功",pdTruckPageInfo);
        }
        return new Result(false, StatusCode.ERROR,"失败",pdTruckPageInfo);

    }

    @Override
    public List<PdTruck> findAll(List<String> ids, String fleetId) {
        LambdaQueryWrapper<PdTruck> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ids != null && ids.size() > 0) {
            lambdaQueryWrapper.in(PdTruck::getId, ids);
        }
        if (StringUtils.isNotEmpty(fleetId)) {
            lambdaQueryWrapper.eq(PdTruck::getFleetId, fleetId);
        }
        lambdaQueryWrapper.eq(PdTruck::getStatus, Constant.DATA_DEFAULT_STATUS);
        lambdaQueryWrapper.orderBy(true, false, PdTruck::getId);
        return baseMapper.selectList(lambdaQueryWrapper);
    }
}
